import huck
import huck.api.keyvalue
import google.appengine.api.memcache

class KeyValue(huck.api.keyvalue.Abstract):

  def add(self, key, value, time=0):
    google.appengine.api.memcache.add(key, value, time)

  def delete(self, key):
    google.appengine.api.memcache.delete(key)

  def get(self, key):
    return google.appengine.api.memcache.get(key)

  def replace(self, key, value, time=0):
    google.appengine.api.memcache.replace(key, value, time)

  def set(self, key, value, time=0):
    google.appengine.api.memcache.set(key, value, time)

  def multi_add(self, mapping, time=0):
    google.appengine.api.memcache.multi_add(mapping, time)

  def multi_delete(self, keys):
    google.appengine.api.memcache.multi_add(keys)

  def multi_get(self, keys):
    return google.appengine.api.memcache.multi_get(keys)

  def multi_replace(self, mapping, time=0):
    google.appengine.api.memcache.multi_replace(mapping, time)

  def multi_set(self, mapping, time=0):
    google.appengine.api.memcache.multi_set(mapping, time)

  def decr(self, key, delta=1, initial_value=None):
    return google.appengine.api.memcache.decr(key, delta, initial_value)

  def incr(self, key, delta=1, initial_value=None):
    return google.appengine.api.memcache.incr(key, delta, initial_value)

class Create(object):

  def __init__(self, type='default'):
    self.type = type

  def setup(self, application):
    huck.api.keyvalue.set(KeyValue, self.type)
    return application
